<#assign module="marketing"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/gird.css">
<link rel="stylesheet" href="${ctx}/assets/css/form.css">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
</@override>
<@override name="body">

	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					添加优惠劵规则
			    </div>
			    <div class="panel-body">
    				<form id="submit_form" class="form-horizontal" method="post">
		               
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>名称：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="title" name="title" type="text" required/>
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>编码：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="code" name="code" type="text" placeholder="编码为1-4位的大写字母" maxlength="4" required/>
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>金额：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="money" name="money" type="text" required/>
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-sm-3 control-label"><em>*</em>有效期：</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="start" name="start" type="text" required/>
		                    </div>
		                    <label style="float:left;" class="control-label">-</label>
		                    <div class="col-sm-3">
		                    	<input class="form-control" id="end" name="end" type="text" required/>
		                    </div>
		                </div>
		                
		                <div class="form-group" style="margin-left:10px;">
			                <label class="col-sm-3 control-label"></label>
			                <input id="submit_button" type="submit" class="btn btn-primary" value="发布">
			                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/notice/list';" value="返回">
			            </div>
					</form>
        		</div>
			</div>
		</div>
	</div>

</@override>
<@override name="footer">
<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#start").datetimepicker({ format: 'yyyy-mm-dd HH:ii', language: 'zh-CN', minView: 'hour', pickDate: true, pickTime: false, inputMask: false, autoclose: true, startDate: new Date()});
		$("#end").datetimepicker({ format: 'yyyy-mm-dd HH:ii', language: 'zh-CN', minView: 'hour', pickDate: true, pickTime: false, inputMask: false, autoclose: true, startDate: new Date()});
		
		$("#submit_form").submit(function(){
			$("#submit_button").attr("disabled",true);
			
			var code=$("#code").val();
			var isE=/^([A-Z]{1,4})$/;
			if(!isE.test(code)){
		       $.scojs_message('无效的编码，编码为1-4位的大写字母', $.scojs_message.TYPE_ERROR);
		       $("#submit_button").attr("disabled",false);
		       return false;
		    }
			
			var money=$("#money").val();
			var reg=/^(-?\d+)(.[0-9]{0,2})?$/;
			if(!reg.test(money)){
		       $.scojs_message('无效的金额，金额必须为数字', $.scojs_message.TYPE_ERROR);
		       $("#submit_button").attr("disabled",false);
		       return false;
		    }
		    
		    if($("#start").val()>=$("#end").val()){
		    	$.scojs_message('结束时间必须大于开始时间', $.scojs_message.TYPE_ERROR);
		    	$("#submit_button").attr("disabled",false);
		    	return false;
		    }
		    
		    $.post("${ctx}/couponrule/create",$("#submit_form").serialize(),function(result){
				if(result.success){
					window.location="${ctx}/couponrule/list";
				}
				else{
					$.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
					$("#submit_button").attr("disabled",false);
				}
			});
		    
			return false;
		});
	
	});
</script>
</@override>
<@extends name="../layout.ftl"/>